import {Component, OnInit} from '@angular/core';
import {LoveRecycManageService} from '../love-recyc-manage.service';
import {DatePipe} from '@angular/common';

enum ORDERSTATE {
  '待上门揽件' = 11,
  '物流运输中' = 13,
  '到货待验机',
  '待确认交易',
  '待打款',
  '打款失败' = 18,
  '打款完成',
  '揽件前取消',
  '验机中',
  '待退回',
  '退回途中',
  '已退回',
  '异常关闭',
}

@Component({
  selector: 'app-recycle-give-idou',
  templateUrl: './recycle-give-idou.component.html',
  styleUrls: ['./recycle-give-idou.component.scss']
})
export class RecycleGiveIdouComponent implements OnInit {
  query = {
    name: '',
    okey: '',
    userType: '',
    orderState: '',
    state: '',
    time: [],
    page: 1, pageSize: 10
  };

  tableData = {
    records: [],
    total: 0
  };
  STATUS = ['-', '待到账', '已到账', '已冻结', '余额不足', '已失效'];
  ORDERSTATE = ORDERSTATE;

  constructor(
    private loveRecycManageService: LoveRecycManageService,
    private datePipe: DatePipe
  ) {
  }

  ngOnInit(): void {
    this.getTableData();
  }


  onPageIndexChange(index: number) {
    this.query.page = index;
    this.getTableData();
  }

  onPageSizeChange(pageSize: number) {
    this.query.pageSize = pageSize;
    this.getTableData();
  }

  getTableData() {
    this.loveRecycManageService.recycleGiveIdouList({
      name: this.query.name,	//  关联活动
      okey: this.query.okey,	//  订单编号
      userType: this.query.userType,	//  用户身份 0 表示游客 1 表示爱思用户
      orderState: this.query.orderState,	//  订单状态
      state: this.query.state,	//  赠送状态
      beginTime: this.datePipe.transform(this.query.time[0], 'yyyy-MM-dd'),	//  下单时间
      endTime: this.datePipe.transform(this.query.time[1], 'yyyy-MM-dd'),	//  下单时间
      page: this.query.page,
      pageSize: this.query.pageSize,
    }).then((res: any) => {
      if (res.code === 0) {
        this.tableData = res.data;
      }
    });
  }

  queryBtn() {
    this.query.page = 1;
    this.getTableData();
  }

  resetCondition() {
    this.query = {
      name: '',
      okey: '',
      userType: '',
      orderState: '',
      state: '',
      time: [],
      page: 1, pageSize: 10
    };
    this.getTableData();
  }
}
